<?php

/*
 * CopyRight  : (C)2012-2099 HaoTeam Inc.
 * Document   : WechatAppAddonFleetGroup.php
 * Created on : 2021-2-28 13:25:55
 * Author     : Tiger <1192851302@qq.com>
 * Description: This is NOT a freeware, use is subject to license terms.
 *              这即使是一个免费软件,使用时也请遵守许可证条款,得到当时人书面许可.
 *              未经书面许可,不得翻版,翻版必究;版权归属 HaoTeam Inc;
 */

namespace miniapp\fleet\model;

use think\Model;
use miniapp\fleet\model\WechatAppAddonFleetGroupUser;

/**
 * 
 * Class WechatAppAddonFleetGroup
 * Tiger <1192851302@qq.com> 2021-2-28 13:25:55
 */
class WechatAppAddonFleetGroup extends Model {

    /**
     * 检查权限
     * @author Tiger <1192851302@qq.com>
     * @return type
     */
    public static function checkAuth() {
        $item = self::where(['mid' => request()->mid(), 'uid' => request()->uid()])->find();
        if (empty($item)) {
            $item = WechatAppAddonFleetGroupUser::getInfo(['mid' => request()->mid(), 'group_user_uid' => request()->uid()]);
        }
        if (empty($item)) {
            json(['code' => 420000, 'msg' => '请申请权限'])->send();
            die();
        }
        return $item;
    }

    /**
     * 
     * @author Tiger <1192851302@qq.com>
     * @param type $where
     * @return type
     */
    public static function be($where) {
        return self::where($where)->count();
    }

    /**
     * 
     * @author Tiger <1192851302@qq.com>
     * @param type $where
     * @return type
     */
    public static function getInfo($where) {
        return self::where($where)->find();
    }

}
